package com.hdu.other.dp.pakege01;

import java.io.*;

public class bytedance006 {

    private static final int MAXN = 501;
    private static int X, SIZE;

    private static final int[] COST = new int[MAXN];
    private static final int[] VALUE = new int[MAXN];

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
        StreamTokenizer st = new StreamTokenizer(reader);

        while (st.nextToken() != StreamTokenizer.TT_EOF) {
            int n = (int) st.nval;
            st.nextToken();
            X = (int) st.nval;
            SIZE = 0;
            long ans = 0;
            for (int i = 0; i < n; i++) {
                st.nextToken();
                int prev = (int) st.nval;
                st.nextToken();
                int cur = (int) st.nval;
                st.nextToken();
                int happy = (int) st.nval;

                int well = prev - cur - cur;
                if (well >= 0) {
                    X += well;
                    ans += happy;
                } else {
                    COST[SIZE] = -well;
                    VALUE[SIZE++] = happy;
                }
            }
            ans += cal();
            writer.println(ans);
        }

        writer.flush();
        writer.close();
        reader.close();
    }

    static long cal() {
        long[] dp = new long[X + 1];
        for (int i = 0; i < SIZE; i++) {
            for (int j = X; j >= COST[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - COST[i]] + VALUE[i]);
            }
        }
        return dp[X];
    }
}
